﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using Nardax.Data.Configuration;

namespace Nardax.Data
{
    public class DatabaseConnectionPolicy
    {
        public static DatabaseConnectionPolicy Default
        {
            get
            {
                var section = ConfigurationManager.GetSection(NardaxDataSection.SectionName) as NardaxDataSection;

                if (section == null)
                {
                    // TODO: add better error message here
                    throw new InvalidOperationException();
                }

                var element = section.DatabaseConnectionPolicies.Get(section.DefaultDatabaseConnectionPolicyName);
                return new DatabaseConnectionPolicy
                           {
                               ConnectionString = element.ConnectionString,
                               DefaultBatchSize = element.DefaultBatchSize,
                               DefaultCommandTimeout = element.DefaultCommandTimeout
                           };
            }
        }

        public string ConnectionString { get; set; }

        public int DefaultCommandTimeout { get; set; }

        public int DefaultBatchSize { get; set; }
    }
}
